package com.yashi.springmvcjbpm.dao.impl;


import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import com.yashi.springmvcjbpm.dao.LeaveDAO;
import com.yashi.springmvcjbpm.entity.Leave;
import com.yashi.springmvcjbpm.util.GetConnection;


@Repository
public class LeaveDAOImpl implements LeaveDAO {
	GetConnection connection = new GetConnection();
	Statement st =null;
	Connection  con  =null;
	public void saveLeave(Leave leave) {
		String sql = "insert into `leave` values ("+leave.getLeaveId()+",'"+leave.getStaffName()+"','"+leave.getLeaveLong()
						+"','"+leave.getLeaveContent()+"','"+leave.getLeaveState()+"','"+leave.getLeaveInstanceId()+"')";
		System.out.println(sql);
		try {
			 con=connection.getCon();
			 st = (Statement) con.createStatement();
			 st.execute(sql);

			} catch (Exception e) {			
				e.printStackTrace();
			}
	}

	
	public void updateLeave(String updateSql) {
		try {
			 con=connection.getCon();
			 st = (Statement) con.createStatement();
			 st.execute(updateSql);

			} catch (Exception e) {			
				e.printStackTrace();
			}
	}

	public List<Leave> findLeaves(String queryString) {
		System.out.println("sql="+queryString);
		List list = new ArrayList();
		try {
			 con=connection.getCon();
			 st = (Statement) con.createStatement();
			 ResultSet rs = st.executeQuery(queryString);
			 list = StaffDAOImpl.resultSetToList(rs);
			} catch (Exception e) {			
				e.printStackTrace();
			}
		System.out.println("list="+list);
		return list;
	}
	public void deleteLeave(String processId) {
		String sql="delete from `leave` where leaveInstanceId='"+processId+"'";
		try {
			 con=connection.getCon();
			 st = (Statement) con.createStatement();
			 st.execute(sql);
			 
			} catch (Exception e) {			
				e.printStackTrace();
			}
	}

	
}
